package com.hmc.modules.sjfx.service.lashen.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmc.common.service.impl.CrudServiceImpl;
import com.hmc.common.constant.Constant;
import com.hmc.modules.sjfx.dao.lashen.LashenDao;
import com.hmc.modules.sjfx.dto.lashen.KlqdDTO;
import com.hmc.modules.sjfx.dto.lashen.LashenDTO;
import com.hmc.modules.sjfx.dto.lashen.QqbDTO;
import com.hmc.modules.sjfx.dto.lashen.QqqdDTO;
import com.hmc.modules.sjfx.entity.lashen.LashenEntity;
import com.hmc.modules.sjfx.service.lashen.LashenService;
import com.hmc.modules.security.user.SecurityUser;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 拉伸
 *
 * @author hmc wengxiulinluman@qq.com
 * @since 3.0 2024-01-05
 */
@Service
public class LashenServiceImpl extends CrudServiceImpl<LashenDao, LashenEntity, LashenDTO> implements LashenService {

    @Autowired
    private LashenDao lashenDao;

    @Override
    public QueryWrapper<LashenEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<LashenEntity> wrapper = new QueryWrapper<>();


        return wrapper;
    }


    /**
     * 查询供应商名称列表
     *
     * @return 供应商名称列表
     */
    @Override
    public List<String> querySupplierNameList() {
        List<String> strings = lashenDao.querySupplierNameList();
        return strings;
    }

    /**
     * 查询所有钢厂的屈强比平均值
     *
     * @return 屈强比平均值
     */
    @Override
    public List<Double> queryYieldRate() {
        List<QqbDTO> longs = lashenDao.queryYieldRate();

        List<String> strings = lashenDao.querySupplierNameList();

        List<Double> qqb = new ArrayList<>();

        for (String string : strings){
            // 创建统计对象
            DescriptiveStatistics stats = new DescriptiveStatistics();
            for (QqbDTO qqbDTO : longs){
                if (qqbDTO.getSupplierName().equals(string)){
                    stats.addValue(Double.parseDouble(qqbDTO.getYieldRate()));
                }
            }
            qqb.add(stats.getMean());
        }
        return qqb;
    }

    /**
     * 查询所有钢厂屈服强度平均值
     *
     * @return 屈服强度平均值
     */
    @Override
    public List<Double> queryYieldStrength() {
        List<String> strings = lashenDao.querySupplierNameList();
        List<Double> qqqd = new ArrayList<>();

        // 查询所有钢厂和屈服强度
        List<QqqdDTO> qqqdDTOS = lashenDao.queryYieldStrength();

        for (String string : strings){
            // 创建统计对象
            DescriptiveStatistics stats = new DescriptiveStatistics();
            for (QqqdDTO qqqdDTO : qqqdDTOS){
                if (qqqdDTO.getSupplierName().equals(string)){
                    stats.addValue(Double.parseDouble(qqqdDTO.getYs()));
                }
            }
            qqqd.add(stats.getMean());
        }

        return qqqd;
    }

    @Override
    public List<Double> queryTensileStrength() {
        List<String> strings = lashenDao.querySupplierNameList();
        List<Double> klqd = new ArrayList<>();

        // 查询所有钢厂和抗拉强度
        List<KlqdDTO> klqdDTOS = lashenDao.queryTensileStrength();
        for (String string : strings){
            // 创建统计对象
            DescriptiveStatistics stats = new DescriptiveStatistics();
            for (KlqdDTO klqdDTO : klqdDTOS){
                if (klqdDTO.getSupplierName().equals(string)){
                    stats.addValue(Double.parseDouble(klqdDTO.getTs()));
                }
            }
            klqd.add(stats.getMean());
        }
        return klqd;
    }


}